<template>
  <div>
    <el-dialog
      title="工单详情"
      :visible="visible"
      width="600px"
      @close="handleClose"
    >
      <div class="head">
        <div class="icon">
          <i v-if="formDetail.taskStatusTypeEntity.statusName !== '待办'" class="el-icon-warning" />
          <i v-else class="el-icon-alarm-clock" />
          <span>{{ formDetail.taskStatusTypeEntity.statusName }}</span>
        </div>
      </div>
      <el-row>
        <el-col :span="12">
          <div class="remark">设备编号: <span>{{ formDetail.innerCode }}</span></div>
          <div v-show="formDetail.taskStatusTypeEntity.statusName !== '待办'" class="remark">取消日期: <span>{{ formDetail.updateTime }}</span></div>
          <div class="remark">工单类型: <span>{{ formDetail.taskType.typeName }}</span></div>
          <div class="remark">工单方式: <span>自动</span></div>
        </el-col>
        <el-col :span="12">
          <div class="remark">创建日期: <span>{{ formDetail.createTime }}</span></div>
          <div class="remark">运营人员: <span>{{ formDetail.userName }}</span></div>
          <div class="remark">补货数量: <a style="color: #85a1ff" @click="lack">补货详情</a></div>
          <div v-if="formDetail.taskStatusTypeEntity.statusName !== '待办'" class="remark">取消原因: <span>{{ formDetail.desc }}</span> </div>
          <div v-else class="remark">备注: <span>{{ formDetail.desc }}</span> </div>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <div class="footer">
          <el-button
            v-if="formDetail.taskStatusTypeEntity.statusName !== '待办'"
            class="cancel"
            type="primary"
            @click="openDetail(formDetail.taskId)"
          >重建工单</el-button>
          <el-button
            v-else
            class="cancel"
            type="primary"
            @click="open"
          >取消工单</el-button>
        </div>
      </span>

      <el-dialog
        title=""
        :visible.sync="dialogVisible"
        width="30%"
        :modal="a"
      >
        <span>取消工单后，将不能恢复，是否确认取消？</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="ensure(formDetail.taskId)">确 定</el-button>
        </span>
      </el-dialog>
    </el-dialog>
    <lackOrder ref="dialog123" :list="list" />
    <WorkOrder ref="WorkOrder" :form-detail="formDetail" :detail-id="detailId" />
  </div>
</template>

<script>
// import { getInfo } from '@/api/table'
import { lackWorkOrder, workOrderDetail } from '@/api/workOrder'
import lackOrder from './lackOrder.vue'
import WorkOrder from './WorkOrder.vue'
export default {
  name: 'DkdElementFindInfo',
  components: {
    lackOrder,
    WorkOrder
  },
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    id: {
      type: Number,
      default: 0
    }
  },
  data () {
    return {
      detailId: 0,
      str: '',
      img: '',
      taskId: '',
      dialogVisible: false,
      list: [],
      a: false,
      formDetail: {
        taskStatusTypeEntity: {
          statusName: '取消'
        },
        taskType: {
          typeName: '补货工单'
        }
      }
    }
  },
  computed: {
  },

  mounted () {
    // this.getInfo()
  },

  methods: {
    openDetail (taskId) {
      this.detailId = +taskId
      this.$nextTick(() => {
        this.$refs.WorkOrder.dialogVisibleOpen()
      })
    },
    async getDetail () {
      const data = await workOrderDetail(this.id)
      this.formDetail = { ...data }
      console.log(this.formDetail)
    },
    handleClose () {
      this.$emit('update:visible', false)
    },
    // async getInfo() {
    //   const res = await this.getInfo(this.taskId)
    //   console.log(res)
    // },
    open () {
      this.dialogVisible = true
    },
    async ensure (id) {
      this.dialogVisible = false
      // console.log(id)
      // this.taskId = id
      // await cancelWorkOrder(this.taskId)
      // this.$message.success('成功')
      this.$message.warning('演示系统，不支持此操作')
      // this.$emit('update:visible', false)
    },
    async lack () {
      const data = await lackWorkOrder(this.formDetail.taskId)
      console.log(data)
      console.log(this.formDetail)

      this.list = data
      this.$refs.dialog123.openDialog()
    }

  }
}
</script>

<style lang="scss" scoped>
.remark {
  margin: 20px 40px;
}
::v-deep .el-dialog {
  border-radius: 10px;
}
.footer {
  text-align: center;
}
.cancel {
   background-color: #fbf4f0 !important;
  color: #655b56 !important;
  border: none;
}
.head {
  width: 100%;
  height: 60px;
  background-color: hsla(0, 0%, 92.5%, 0.39);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  i {
    font-size: 30px;
  }
  .green {
    color: lawngreen;
  }
  span {
    font-size: 16px;
    margin-left: 20px;
  }
}
.box {
  width: 590px;
  height: 180px;
  // background-color: #ccc;
  padding-left: 30px;
  padding-right: 15px;
  .bigbox {
    display: flex;
    justify-content: space-between;
    margin-bottom: 24px;
    .al{
      color: #5f84ff;
    }
  }
  .box1 {
    margin-top: 40px;
  }
}
</style>
